//
//  SEGBillDiscountRuleTableViewCell.m
//  SEGUhomePropertyBaseService
//
//  Created by Clavis on 2019/3/4.
//  Copyright © 2019 刘山. All rights reserved.
//

#import "SEGBillDiscountRuleTableViewCell.h"

@interface SEGBillDiscountRuleTableViewCell ()

@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation SEGBillDiscountRuleTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView *backImageView = ({
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageWithContentsOfFile:SEGPicName(@"pic_bg_youhui")];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.layer.masksToBounds = YES;
        imageView.layer.cornerRadius = 2;
        [self.contentView addSubview:imageView];
        imageView;
    });
    [backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-10);
    }];
    
    UIImageView *iconImageView = ({
        UIImageView *imageView = [[UIImageView alloc] init];
        imageView.image = [UIImage imageWithContentsOfFile:SEGPicName(@"icon_youhui")];
        [self.contentView addSubview:imageView];
        imageView;
    });
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backImageView.mas_top).offset(15);
        make.left.equalTo(backImageView.mas_left).offset(15);
        make.width.mas_equalTo(22);
    }];
    
    self.titleLabel = ({
        UILabel *lable = [[UILabel alloc] init];
        [self.contentView addSubview:lable];
        lable.textColor = [UIColor colorWithHexString:@"#CA7C00"];
        lable.font = kFont_15;
        lable.numberOfLines = 0;
        lable;
    });
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(18);
        make.left.equalTo(iconImageView.mas_right).offset(10);
        make.right.equalTo(backImageView.mas_right).offset(-20);
    }];
    
    UILabel *joinLabel = ({
        UILabel *lable = [[UILabel alloc] init];
        [self.contentView addSubview:lable];
        lable.textColor = [UIColor colorWithHexString:@"#CA7C00"];;
        lable.font = kFont_11;
        lable.text = @"一键参与";
        lable.layer.borderColor = [UIColor colorWithHexString:@"#CA7C00"].CGColor;
        lable.layer.borderWidth = 1;
        lable.layer.cornerRadius = 9;
        lable.layer.masksToBounds = YES;
        lable.textAlignment = NSTextAlignmentCenter;
        lable;
    });
    [joinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(53);
        make.height.mas_equalTo(18);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(15);
        make.bottom.equalTo(backImageView).offset(-10);
        make.right.equalTo(backImageView).offset(-15);
    }];
    
    UIButton *joinButton = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(joinButtonTap:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:button];
        button;
    });
    [joinButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(backImageView);
    }];
    
    UIView *leftCircle = ({
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = kColor_W;
        [self.contentView addSubview:view];
        CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
        UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(0, 7.5) radius:7.5 startAngle:1.5*M_PI endAngle:0.5*M_PI clockwise:YES];
        shapeLayer.path = path.CGPath;
        view.layer.mask = shapeLayer;
        view;
    });
    [leftCircle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(15);
        make.left.equalTo(backImageView.mas_left);
        make.centerY.equalTo(backImageView);
    }];
    
    UIView *rightCircle = ({
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = kColor_W;
        [self.contentView addSubview:view];
        CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
        UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(8, 7.5) radius:7.5 startAngle:1.5*M_PI endAngle:0.5*M_PI clockwise:NO];
        shapeLayer.path = path.CGPath;
        view.layer.mask = shapeLayer;
        view;
    });
    [rightCircle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(15);
        make.right.equalTo(backImageView.mas_right);
        make.centerY.equalTo(backImageView);
    }];
    
}

- (void)joinButtonTap:(UIButton *)sender {
    if (self.joinBlock) {
        self.joinBlock();
    }
}

- (void)updateTitle:(NSString *)title {
    self.titleLabel.text = title;
}
@end
